import request from '@/utils/request'
import qs from 'qs'

export function setEndTime(time) {
  return request({
    url: '/system/tableFour/setendtime',
    method: 'post',
    data: qs.stringify({time})
  })
}

/**
 * 获取本人的用户信息
 * @param limit
 * @param offset
 */
export function getMyUserInfo() {
  return request({
    url: '/system/baseSysUser/getMyUserInfo',
    method: 'post'
  })
}

/**
 * 获取列表
 * @param limit
 * @param offset
 */
export function page(limit, offset, userName, nickName, phone, deptId) {
  return request({
    url: '/system/baseSysUser/getPage',
    method: 'post',
    data: qs.stringify({
      limit,
      offset,
      userName,
      nickName,
      phone,
      deptId
    })
  })
}

/**
 * 导入用户
 * @param id
 */
export function readExcel(url) {
  return request({
    url: '/system/baseSysUser/readExcel',
    method: 'post',
    data: qs.stringify({
      url
    })
  })
}

/**
 * 获取详情
 * @param id
 */
export function getInfo(id) {
  return request({
    url: '/system/baseSysUser/getInfo',
    method: 'post',
    data: qs.stringify({
      id
    })
  })
}

/**
 * 重置密码
 * @param id
 */
export function resetting(id) {
  return request({
    url: '/system/baseSysUser/resetting',
    method: 'post',
    data: qs.stringify({
      id
    })
  })
}

/**
 * 删除
 * @param id
 */
export function delInfo(id) {
  return request({
    url: '/system/baseSysUser/del',
    method: 'post',
    data: qs.stringify({
      id
    })
  })
}

/**
 * 新增或编辑
 * @param id
 * @param name
 * @param menuKey
 * @param pId
 * @param type
 */
export function addOrEdit(id, userName, nickName, roleKey, phone, headUrl, deptId, postId, practiceNum, supervisor, supervisorDeptIdJson, director, resignationTime,
                          groupLeader, idCard, dzyx, workcode, oaUserId, positiveTime, practiceTime, signature) {
  return request({
    url: '/system/baseSysUser/addOrEdit',
    method: 'post',
    data: qs.stringify({
      id,
      userName,
      nickName,
      roleKey,
      phone,
      headUrl,
      deptId,
      postId, practiceNum,
      supervisor,
      supervisorDeptIdJson,
      director,
      resignationTime,
      groupLeader, idCard, dzyx, workcode, oaUserId, positiveTime, practiceTime, signature
    })
  })
}

/**
 * 用户排序
 * @param pId
 * @param id
 * @param sort
 */
export function userSort(pId, id, sort) {
  return request({
    url: '/system/baseSysUser/userSort',
    method: 'post',
    data: qs.stringify({
      pId, id, sort
    })
  })
}

export function setHeadUrl(headUrl) {
  return request({
    url: '/system/baseSysUser/setHeadUrl',
    method: 'post',
    data: qs.stringify({
      headUrl
    })
  })
}

/**
 * 获取所有用户
 */
export function allUserList() {
  return request({
    url: '/system/baseSysUser/allList',
    method: 'post'
  })
}

/**
 * 获取部门所有用户
 */
export function getDeptUserList(deptId) {
  return request({
    url: '/system/baseSysUser/getDeptUserList',
    method: 'post',
    data: qs.stringify({
      deptId
    })
  })
}

/**
 * 获取所有职位
 */
export function allPostList() {
  return request({
    url: '/system/basePost/getAll',
    method: 'post'
  })
}

/**
 * 获取所有用户
 * @returns {AxiosPromise}
 */
export function getUserList() {
  return request({
    url: '/system/baseSysUser/getUserList',
    method: 'post'
  })
}
